import json

import requests

from wechat_api.api.base_api import BaseApi


class WeWork(BaseApi):
    #声明变量
    token=None

    def get_token(self):
        data={
            'url':"https://qyapi.weixin.qq.com/cgi-bin/gettoken",
            'method':'get',
            'params':{"corpid": "wwdbb757a9107c22d4",
                      "corpsecret": "EZvjYGJcD6Ov2ICMlAeprrUmxVWXV7d1V7UrOjZr9-Q"
            }
        }
        r = self.request(data)
        # r = requests.get(url="https://qyapi.weixin.qq.com/cgi-bin/gettoken",
        #                  params={"corpid": "wwdbb757a9107c22d4",
        #                          "corpsecret": "EZvjYGJcD6Ov2ICMlAeprrUmxVWXV7d1V7UrOjZr9-Q"}
        #                  )  # 建立请求
        # print(json.dumps(r.json(), indent=2, ensure_ascii=False))  # 优化json格式
        assert r.status_code == 200  # 断言
        print(r.json()['access_token'])  # 打印token信息
        self.token = r.json()['access_token']  # 将token存入变量


    # def search(self):
    #     r = requests.post(url="https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_corp_tag_list",
    #                       params={"access_token": self.token},
    #                       json={}
    #                       )
    #     print(json.dumps(r.json(), indent=2, ensure_ascii=False))
    #     return r
    #
    # def add(self, tag_name, group_name):
    #     r = requests.post(
    #         "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_corp_tag",
    #         params={"access_token": self.token},
    #         json={
    #             "group_name": group_name,
    #             "tag":
    #                 [
    #                     {"name": tag_name}
    #                 ]
    #         }
    #     )
    #     print(json.dumps(r.json(), indent=2, ensure_ascii=False))
    #     return r
    #
    # def modify(self, tag_id, new_tag_name):
    #     r = requests.post(
    #         "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/edit_corp_tag",
    #         params={"access_token": self.token},
    #         json={
    #                     "id": tag_id,
    #                     "name": new_tag_name
    #              }
    #     )
    #     print(json.dumps(r.json(), indent=2, ensure_ascii=False))
    #     return r
    #
    # def delete(self, tag_id):
    #     r = requests.post(
    #         "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/del_corp_tag",
    #         params={"access_token": self.token},
    #         json={
    #             "tag_id": tag_id
    #         }
    #     )
    #     print(json.dumps(r.json(), indent=2, ensure_ascii=False))
    #     return r